package com.carkeeper.appraise.controller;

import com.carkeeper.appraise.pojo.Appraisal;
import com.carkeeper.appraise.service.AppraisalService;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/appraisal")
public class AppraisalController {
    @Autowired
    private AppraisalService appraisalService;
    /**
     * 查询字段delete为o的所有数据
     * @return
     */
    @GetMapping("/findAll")
    public Result<List<Appraisal>> findAll(){
        try {
            List<Appraisal> list = appraisalService.findAll();
            return new Result<List<Appraisal>>(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            return new Result<List<Appraisal>>(false, StatusCode.ERROR,"查询失败");
        }
    }
    @PostMapping("/add")
    public Result add(@RequestBody Appraisal appraisal){
        try {
            int i = appraisalService.add(appraisal);
            if(i>0){
            return new Result(true, StatusCode.OK,"添加成功");
            }
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
        return new Result(false, StatusCode.ERROR,"添加失败");
    }

}
